package com.itheima.controller;

import com.itheima.common.entity.PageResult;
import com.itheima.common.entity.QueryPageBean;
import com.itheima.common.entity.Result;
import com.itheima.pojo.CheckGroup;
import com.itheima.pojo.CheckPageQueryDTO;
import com.itheima.pojo.Setmeal;
import com.itheima.service.SetmealService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/setmeal")
@Api(tags = "套餐相关接口")
public class SetmealController {

    @Autowired
    private SetmealService setmealService;

    /**
     * 新增套餐
     * @param setmeal
     * @param checkgroupIds
     * @return
     */
    @PostMapping("/add")
    @ApiOperation("新增套餐")
    public Result add (@RequestBody Setmeal setmeal, @RequestParam List<Integer> checkgroupIds) {
        log.info("新增检查组:{}",setmeal);
        setmealService.add(setmeal,checkgroupIds);
        return Result.success();
    }


    /**
     * 修改套餐
     * @param setmeal
     * @param checkgroupIds
     * @return
     */
    @PutMapping("/edit")
    @ApiOperation("修改套餐")
    public Result update (@RequestBody Setmeal setmeal, @RequestParam List<Integer> checkgroupIds) {
        log.info("修改套餐:{}",setmeal);
        setmealService.updateById(setmeal,checkgroupIds);
        return Result.success();
    }

    /**
     * 根据主键ID进行套餐查询
     * @param id
     * @return
     */
    @GetMapping("/findById/{id}")
    @ApiOperation("根据主键ID进行套餐查询")
    public Result<Setmeal> geyById (@PathVariable Long id) {
        log.info("根据主键ID进行套餐查询：{}",id);
        Setmeal setmeal = setmealService.geyById(id);
        return Result.success(setmeal);
    }

    /**
     * 套餐分页查询
     * @param queryPageBean
     * @return
     */
    @PostMapping("/findPage")
    @ApiOperation("套餐分页查询")
    public Result<PageResult> page(@RequestBody QueryPageBean queryPageBean){
        log.info("套餐分页查询：{}", queryPageBean);
        PageResult pageResult = setmealService.pageQuery(queryPageBean);
        return Result.success(pageResult);
    }

}
